<template>
  <div>
    <el-container style="background: #f5f7f9;">
      <el-header style="background: #fff;padding: 12px 12px;height:auto;">
        <div>
          <el-form :model="queryData" :inline="true" size="small">
            <el-form-item label="客户">
              <el-select v-model="queryData.orgOwner" clearable filterable>
                <el-option v-for="(d, i) in customerOptions" :key="i" :label="d.orgOwnerName" :value="d.orgOwner" />
              </el-select>
            </el-form-item>
            <el-form-item label="批次号">
              <el-input v-model="batchAttribute" type="textarea" :rows="1" style="width: 320px;" placeholder="多个订单号用回车分割，支持批次号、提单号" />
            </el-form-item>
            <el-form-item label="状态">
              <el-select v-model="queryData.operationStatus" filterable clearable placeholder="选择状态">
                <el-option v-for="(d, i) in operationStatusOption" :key="i" :label="d.name" :value="d.id" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="list">搜索</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-header>
      <el-main style="margin-top: 15px; background: #fff;padding: 12px 16px 0 16px;height: 100%;">
        <div style="height: 100%;display: flex;">
          <el-radio-group v-model="statusRadio" @change="statusChange">
            <el-radio-button v-for="(d) in stageOptions" :key="d.id" :label="d.name" />
          </el-radio-group>
        </div>
        <el-table
          ref="table"
          :data="table_body"
          border
          :max-height="tableHeight"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column prop="batchNumber" label="批次号" fixed />
          <el-table-column prop="orgOwnerName" label="客户" />
          <el-table-column prop="typeName" label="类型" />
          <el-table-column v-if="statusRadio !=='完成' " prop="operationStatus" label="状态" />
          <el-table-column prop="attrs.BA2" label="起运地" />
          <el-table-column prop="attrs.BA3" label="目的地" />
          <el-table-column prop="serviceTypeName" width="300" label="服务类型" />
          <el-table-column prop="createdAt" label="创建时间" />
          <el-table-column prop="attrs.BA1" label="提单号/柜号" />
          <el-table-column prop="totalCarton" label="总件数" />
          <el-table-column prop="totalCartonFedex" label="FEDEX件数" />
          <el-table-column prop="totalCartonUps" label="UPS件数" />
          <el-table-column prop="totalCartonTruck" label="卡派件数">
            <template slot-scope="scope">
              <a style="text-decoration:underline;" @click="showTruckDetail(scope.row)">{{ scope.row.totalCartonTruck }}</a>
            </template>
          </el-table-column>
          <el-table-column prop="totalCartonStockIn" label="留仓件数" />
          <el-table-column prop="totalWeight" label="总毛重" />
          <el-table-column prop="attrs.BA4" label="起飞/开船时间" />
          <el-table-column prop="attrs.BA5" label="落地/到港时间" />
          <el-table-column prop="attrs.BA19" label="仓库" />
          <el-table-column prop="attrs.BA20" label="ATA" />
          <el-table-column prop="attrs.BA21" label="ATD" />
          <el-table-column prop="attrs.BA22" label="清关时间" />
          <el-table-column prop="attrs.BA23" label="交服务商时间" />
          <el-table-column prop="attrs.BA24" label="FEDEX上网时间" />
          <el-table-column prop="attrs.BA25" label="UPS上网时间" />
          <el-table-column prop="attrs.BA7" label="操作说明" />
          <el-table-column prop="attrs.BA6" label="派送地址" />
          <el-table-column prop="attrs.BA8" label="提单发货人" />
          <el-table-column prop="attrs.BA9" label="提单收货人" />
          <el-table-column prop="attrs.BA10" label="提单通知方" />
          <el-table-column prop="attrs.BA27" label="到达仓库时间" />
          <el-table-column prop="attrs.BA28" label="拆柜时间" />
          <el-table-column prop="attrs.BA29" label="交柜时间" />
          <el-table-column prop="attrs.BA30" label="仓库备注" />
          <el-table-column label="附件下载" width="200px" fixed="right">
            <template slot-scope="scope">
              <div v-if="statusRadio !=='完成' ">
                <el-button v-if="scope.row.attrs.BA11" size="mini" type="text" @click="downloadFile(scope.row.attrs.BA11)">提单下载<span style="color:red;">{{ scope.row.attrsUpdated.BA11 ? "(更新)" : "" }}</span></el-button>
                <el-button v-if="scope.row.attrs.BA12" size="mini" type="text" @click="downloadFile(scope.row.attrs.BA12)">清关资料下载<span style="color:red;">{{ scope.row.attrsUpdated.BA12 ? "(更新)" : "" }}</span></el-button>
                <el-button v-if="scope.row.attrs.BA13" size="mini" type="text" @click="downloadFile(scope.row.attrs.BA13)">物品描述下载<span style="color:red;">{{ scope.row.attrsUpdated.BA13 ? "(更新)" : "" }}</span></el-button>
                <el-button v-if="scope.row.attrs.BA14" size="mini" type="text" @click="downloadFile(scope.row.attrs.BA14)">ISF申报表下载<span style="color:red;">{{ scope.row.attrsUpdated.BA14 ? "(更新)" : "" }}</span></el-button>
                <el-button v-if="scope.row.attrs.BA15" size="mini" type="text" @click="downloadFile(scope.row.attrs.BA15)">FDRA文件下载<span style="color:red;">{{ scope.row.attrsUpdated.BA15 ? "(更新)" : "" }}</span></el-button>
                <el-button v-if="scope.row.attrs.BA16" size="mini" type="text" @click="downloadFile(scope.row.attrs.BA16)">卡派明细表下载<span style="color:red;">{{ scope.row.attrsUpdated.BA16 ? "(更新)" : "" }}</span></el-button>
              </div>
              <div v-else>
                <el-button v-if="scope.row.attrs.BA11" size="mini" type="text" @click="downloadFile(scope.row.attrs.BA11)">提单下载</el-button>
                <el-button v-if="scope.row.attrs.BA12" size="mini" type="text" @click="downloadFile(scope.row.attrs.BA12)">清关资料下载</el-button>
                <el-button v-if="scope.row.attrs.BA13" size="mini" type="text" @click="downloadFile(scope.row.attrs.BA13)">物品描述下载</el-button>
                <el-button v-if="scope.row.attrs.BA14" size="mini" type="text" @click="downloadFile(scope.row.attrs.BA14)">ISF申报表下载</el-button>
                <el-button v-if="scope.row.attrs.BA15" size="mini" type="text" @click="downloadFile(scope.row.attrs.BA15)">FDRA文件下载</el-button>
                <el-button v-if="scope.row.attrs.BA16" size="mini" type="text" @click="downloadFile(scope.row.attrs.BA16)">卡派明细表下载</el-button>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" fixed="right">
            <template slot-scope="scope">
              <el-dropdown style="margin-top:10px;">
                <el-button plain size="small">...</el-button>
                <el-dropdown-menu slot="dropdown">
                  <template v-if="statusRadio !=='完成' ">
                    <el-dropdown-item size="mini" type="text" @click.native="edit(scope.row)">
                      编辑
                    </el-dropdown-item>
                    <el-dropdown-item size="mini" type="text" @click.native="done(scope.row)">
                      完成
                    </el-dropdown-item>
                    <el-dropdown-item size="mini" type="text" @click.native="deleteBatch(scope.row)">
                      删除
                    </el-dropdown-item>
                    <el-dropdown-item size="mini" type="text" @click.native="processed(scope.row)">
                      已处理
                    </el-dropdown-item>
                  </template>
                  <el-dropdown-item size="mini" type="text" @click.native="downloadPackingList(scope.row)">
                    打单表导出
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
      <el-footer style="padding:0;background: #fff;">
        <div style="text-align: right; padding-top: 10px;">
          <el-pagination
            background
            :current-page="queryData.currentPage"
            :page-sizes="pageSizes"
            :page-size="queryData.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pageTotal"
            style="float: right;"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </el-footer>
    </el-container>
    <!-- 新增批次-填写属性 -->
    <el-dialog title="新建提单" :visible.sync="dialogAddVisible" :close-on-click-modal="false" top width="60%">
      <el-form class="edit-form" label-position="top">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="类型">
              <el-select v-model.lazy="formData.type" class="width-inline" placeholder="选择类型" style="width:100%;" @change="typeChanged">
                <el-option v-for="(d,i) in types" :key="i" :label="d.name" :value="d.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="服务类型(请选择你所需的服务,可以多选)">
              <el-select v-model="formData.serviceType" :disabled="editing" multiple class="width-inline" placeholder="选择服务类型" style="width:100%;">
                <el-option v-for="(d) in serviceTypeList" :key="d.id" :label="d.name" :value="d.id" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="起运地">
              <el-input v-model.lazy="formDataAttrs.BA2" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="目的地">
              <el-select v-model="formDataAttrs.BA3" class="width-inline" placeholder="选择目的地" style="width:100%;">
                <el-option v-for="(d,i) in endPlaceList" :key="i" :label="d" :value="d" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="提单号/柜号">
              <el-input v-model.lazy="formDataAttrs.BA1" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="起飞/开船时间">
              <el-date-picker v-model.lazy="formDataAttrs.BA4" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss" style="width:100%;" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="落地/到港时间">
              <el-date-picker v-model.lazy="formDataAttrs.BA5" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss" style="width:100%;" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总毛重KG">
              <el-input v-model.lazy="formData.totalWeight" type="number" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="提单发货人">
              <el-input v-model.lazy="formDataAttrs.BA8" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="提单收货人">
              <el-input v-model.lazy="formDataAttrs.BA9" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="提单通知方">
              <el-input v-model.lazy="formDataAttrs.BA10" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="FEDEX件数">
              <el-input v-model.lazy="formData.totalCartonFedex" type="number" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="UPS件数">
              <el-input v-model.lazy="formData.totalCartonUps" type="number" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="卡派件数">
              <el-input v-model.lazy="formData.totalCartonTruck" type="number" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="留仓件数">
              <el-input v-model.lazy="formData.totalCartonStockIn" type="number" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item v-show="showBindOrder" label="请输入卡派订单号">
              <el-input v-model.lazy="formData.orderNumbers" type="textarea" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="仓库">
              <el-input v-model.lazy="formDataAttrs.BA19" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="ATA">
              <el-input v-model.lazy="formDataAttrs.BA20" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="ATD">
              <el-input v-model.lazy="formDataAttrs.BA21" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="清关时间">
              <el-date-picker v-model.lazy="formDataAttrs.BA22" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss" style="width:100%;" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="交服务商时间">
              <el-date-picker v-model.lazy="formDataAttrs.BA23" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss" style="width:100%;" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预约入仓时间">
              <el-date-picker v-model.lazy="formDataAttrs.BA26" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss" style="width:100%;" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="操作说明" style="">
              <el-input v-model.lazy="formDataAttrs.BA7" type="textarea" :rows="2" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="派送地址">
              <el-input v-model.lazy="formDataAttrs.BA6" type="textarea" :rows="2" />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 上传资料 -->
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="提单表">
              <el-upload
                :action="uploadUrl"
                name="file"
                :with-credentials="true"
                :limit="1"
                list-type="text"
                :on-remove="handleRemove"
                :on-success="uploadCallback1"
                :file-list="fileList"
                style="display: inline-block;"
              >
                <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="清关资料">
              <el-upload
                :action="uploadUrl"
                name="file"
                :with-credentials="true"
                :limit="1"
                list-type="text"
                :on-remove="handleRemove2"
                :on-success="uploadCallback2"
                :file-list="fileList2"
                style="display: inline-block;"
              >
                <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="物品描述">
              <el-upload
                :action="uploadUrl"
                name="file"
                :with-credentials="true"
                :limit="1"
                list-type="text"
                :on-remove="handleRemove3"
                :on-success="uploadCallback3"
                :file-list="fileList3"
                style="display: inline-block;"
              >
                <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="ISF申报表">
              <el-upload
                :action="uploadUrl"
                name="file"
                :with-credentials="true"
                :limit="1"
                list-type="text"
                :on-remove="handleRemove4"
                :on-success="uploadCallback4"
                :file-list="fileList4"
                style="display: inline-block;"
              >
                <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="FDRA文件">
              <el-upload
                :action="uploadUrl"
                name="file"
                :with-credentials="true"
                :limit="1"
                list-type="text"
                :on-remove="handleRemove5"
                :on-success="uploadCallback5"
                :file-list="fileList5"
                style="display: inline-block;"
              >
                <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="卡派明细表">
              <el-upload
                :action="uploadUrl"
                name="file"
                :with-credentials="true"
                :limit="1"
                list-type="text"
                :on-remove="handleRemove6"
                :on-success="uploadCallback6"
                :file-list="fileList6"
                style="display: inline-block;"
              >
                <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogAddVisible = false">取 消</el-button>
        <el-button size="small" type="primary" @click="add">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="truckDetailDialog"
      width="30%"
    >
      <el-table
        :data="truck_table_body"
        border
        style="width: 100%;"
        max-height="800"
        class="order-charge__table"
      >
        <el-table-column prop="orderNumber" label="订单号" />
        <el-table-column prop="totalCarton" label="总箱数" />
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
import { mapState } from 'vuex'
import request from '@/utils/request'
import { copyProperty, copyAllProperty } from '@/utils/tools'
import config from '@/settings'
import dateFormat from 'dateformat'
const BASE_URL = process.env.NODE_ENV === 'development' ? config.baseUrl.dev : config.baseUrl.pro
export default {
  data() {
    return {
        truckDetailDialog: false,
        editing: false,
        uploadUrl: BASE_URL + '/upload',
        statusRadio: '申报ISF',
        fileList: [],
        fileList2: [],
        fileList3: [],
        fileList4: [],
        fileList5: [],
        fileList6: [],
        table_body: [],
        truck_table_body: [],
        pageTotal: 0,
        dialogAddVisible: false,
        multipleSelection: [],
        batchAttribute: '',
        formDataDefault: {
            batchId: '',
            type: '',
            serviceType: [],
            totalWeight: '',
            totalCartonFedex: '',
            totalCartonUps: '',
            totalCartonTruck: '',
            totalCartonStockIn: '',
            orderNumbers: ''
        },
        formData: {
            batchId: '',
            type: '',
            serviceType: [],
            totalWeight: '',
            totalCartonFedex: '',
            totalCartonUps: '',
            totalCartonTruck: '',
            totalCartonStockIn: '',
            orderNumbers: ''
        },
      formDataDefaultAttrs: {
            BA1: '',
            BA2: '',
            BA3: '',
            BA4: '',
            BA5: '',
            BA6: '',
            BA7: '',
            BA8: '',
            BA9: '',
            BA10: '',
            BA11: '',
            BA12: '',
            BA13: '',
            BA14: '',
            BA15: '',
            BA16: '',
            BA17: '',
            BA18: '',
            BA19: '',
            BA20: '',
            BA21: '',
            BA22: '',
            BA23: '',
            BA24: '',
            BA25: ''
      },
      formDataAttrs: {
            BA1: '',
            BA2: '',
            BA3: '',
            BA4: '',
            BA5: '',
            BA6: '',
            BA7: '',
            BA8: '',
            BA9: '',
            BA10: '',
            BA11: '',
            BA12: '',
            BA13: '',
            BA14: '',
            BA15: '',
            BA16: '',
            BA17: '',
            BA18: '',
            BA19: '',
            BA20: '',
            BA21: '',
            BA22: '',
            BA23: '',
            BA24: '',
            BA25: ''
        },
        endPlaceList: [
            'LAX',
            'JFK',
            'EWR',
            'LA',
            'LB',
            '其它'
        ],
      serviceTypeList: [],
      serviceTypeListSea: [],
      serviceTypeListAir: [],
      serviceTypeListMap: new Map(),
      // 分页的数据
      pageSizes: [50, 100, 500],
      total: 0,
      types: [
          { id: 'AIR', name: '空运' },
          { id: 'SEA', name: '海运' }
          // { id: 'GND', name: '铁运' }
      ],
      queryData: {
        pageSize: 50,
        currentPage: 1,
        status: '',
        stages: [1],
        operationStatus: ''
      },
      stageOptions: [],
      operationStatusOption: [],
      idToStageName: new Map(),
      currentStageId: 1
    }
  },
  computed: {
    tableHeight() {
      return document.documentElement.clientHeight - 290
    },
    ...mapState(//
      {
        customerOptions: state => state.base.customerOptions,
        profile: state => state.user
      }
    ),
    isOrgOwner() {
      return this.profile.orgOwner
    },
    showBindOrder() {
      if (this.formData.totalCartonTruck && this.formData.totalCartonTruck > 0) {
          return true
      } else {
          return false
      }
    }
  },
  created() {
    this.loadStageOption()
    this.initBatchServiceType()
    this.list()
    this.loadOperationStatusOption()
  },
  methods: {
    downloadPackingList(row) {
      window.open(BASE_URL + '/batch/download-packing-list?id=' + row.batchId)
    },
    showTruckDetail(row) {
      if (row.totalCartonTruck === 0) {
        this.truck_table_body = []
        return
      }
      this.truckDetailDialog = true
      request({
        url: 'batch/truck?batchId=' + row.batchId,
        method: 'get'
      }).then(res => {
        if (res.success) {
          this.truck_table_body = res.data
        }
      })
    },
    loadStageOption() {
      request({
        url: 'batch/stage/option/all',
        method: 'get'
      }).then(res => {
        if (res.success) {
          this.stageOptions = res.data
          res.data.forEach(e => {
            this.idToStageName.set(e.name, e.id)
          })
        }
      })
    },
    loadOperationStatusOption() {
      request({
        url: 'batch/operation-status-option',
        method: 'get'
      }).then(res => {
        if (res.success) {
          this.operationStatusOption = res.data
        }
      })
    },
    typeChanged(v) {
      switch (v) {
        case 'SEA':
          this.serviceTypeList = this.serviceTypeListSea
          break
          case 'AIR':
            this.serviceTypeList = this.serviceTypeListAir
            break
      }
      this.formData.serviceType = []
    },
    serviceTypeChanged(v) {
      v.forEach(ele => {
        const st = this.serviceTypeListMap.get(ele)
        switch (st.name) {
          case '交UPS':
            this.show2 = true
            break
            case '交FEDEX':
              this.show1 = true
              break
            case '卡派':
              this.show3 = true
              break
            case '留仓':
              this.show4 = true
              break
            case '整柜直送':
              this.show5 = true
              break
        }
      })
    },
    list() {
      if (this.batchAttribute) {
        this.queryData.batchAttributes = this.batchAttribute.split(/,|\n|，/)
      } else {
        this.queryData.batchAttributes = []
      }
      request({
        url: 'batch/query',
        method: 'post',
        data: this.queryData
      }).then(res => {
        if (res.success) {
          if (res.data) {
            this.table_body = res.data.records
            this.pageTotal = res.data.total
          }
        }
      })
    },
    add() {
      const formDataTemp = {
        attrs: []
      }
      copyAllProperty(formDataTemp, this.formData, true)
      for (const key in this.formDataAttrs) {
        formDataTemp.attrs.push({ 'key': key, value: this.formDataAttrs[key] instanceof Date ? dateFormat(this.formDataAttrs[key], 'yyyy-mm-dd') : this.formDataAttrs[key] })
      }
      if (this.formData.totalCartonTruck && this.formData.totalCartonTruck !== '0' && !this.formData.orderNumbers) {
        this.$notify({
            title: '提示',
            message: '请输入卡派订单号',
            type: 'warning'
        })
        return false
      }
      request({
        url: 'batch/add',
        method: 'post',
        data: formDataTemp
      }).then(res => {
        if (res.success) {
          this.dialogAddVisible = false
          this.list()
          copyProperty(this.formData, this.formDataDefault)
          copyProperty(this.formDataAttrs, this.formDataDefaultAttrs)
        }
      })
    },
    edit(row) {
      this.fileList = []
      this.fileList2 = []
      this.fileList3 = []
      this.fileList4 = []
      this.fileList5 = []
      this.fileList6 = []
      copyProperty(this.formData, this.formDataDefault)
      copyProperty(this.formDataAttrs, this.formDataDefaultAttrs)
      this.typeChanged(row.type)
      copyProperty(this.formData, row)
      copyProperty(this.formDataAttrs, row.attrs)
      this.formData.orderNumbers = row.orderNumbers
      this.editing = true
      this.dialogAddVisible = true
    },
    statusChange(status) {
      if (status === '完成') {
        this.queryData.status = 'done'
      } else {
        const id = this.idToStageName.get(status)
        this.queryData.stages = [id]
        this.queryData.status = ''
        this.currentStageId = id
      }
        this.queryData.pageSize = 50
        this.queryData.currentPage = 1
        this.list()
    },
    done(row) {
      request({
        url: 'batch/stage-done?batchId=' + row.batchId + '&stageId=' + this.currentStageId,
        method: 'get'
      }).then(res => {
        if (res.success) {
           this.list()
        }
      })
    },
    deleteBatch(row) {
        this.$confirm(row.batchNumber + '批次是否删除？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            dangerouslyUseHTMLString: true,
            type: 'warning'
        }).then(() => {
            request({
                url: 'batch/del?batchId=' + row.batchId,
                method: 'get'
            }).then(res => {
                if (res.success) {
                    this.list()
                }
            })
        })
    },
    processed(row) {
        this.$confirm(row.batchNumber + '批次是否已处理？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            dangerouslyUseHTMLString: true,
            type: 'warning'
        }).then(() => {
            request({
                url: 'batch/processed?batchId=' + row.batchId,
                method: 'get'
            }).then(res => {
                if (res.success) {
                    this.list()
                }
            })
        })
    },
      uploadCallback1(res) {
          this.formDataAttrs.BA11 = res.ossKey
      },
      uploadCallback2(res) {
          this.formDataAttrs.BA12 = res.ossKey
      },
      uploadCallback3(res) {
          this.formDataAttrs.BA13 = res.ossKey
      },
      uploadCallback4(res) {
          this.formDataAttrs.BA14 = res.ossKey
      },
      uploadCallback5(res) {
          this.formDataAttrs.BA15 = res.ossKey
      },
      uploadCallback6(res) {
          this.formDataAttrs.BA16 = res.ossKey
      },
      // 分页
    handleSizeChange(val) {
      this.queryData.pageSize = val
      this.queryData.currentPage = 1
      this.list()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.list()
    },
    initBatchServiceType() {
      const _this = this
      request({
        url: 'batch/service-type/option',
        method: 'get'
      }).then(res => {
        if (res.success) {
          res.data.forEach(ele => {
            if (!ele.type) {
              _this.serviceTypeListAir.push(ele)
              _this.serviceTypeListSea.push(ele)
            } else if (ele.type === 'SEA') {
              _this.serviceTypeListSea.push(ele)
            } else if (ele.type === 'AIR') {
              _this.serviceTypeListAir.push(ele)
            }
            _this.serviceTypeListMap.set(ele.id, ele)
          })
        }
      })
    },
    exportOrderCost() {
    },
    clearFileList() {
        // 清空
        this.fileList = []
        this.fileList2 = []
        this.fileList3 = []
        this.fileList4 = []
        this.fileList5 = []
        this.fileList6 = []
    },
    downloadFile(ossKey) {
       request({
        url: 'download?ossKey=' + ossKey,
        method: 'get'
      }).then(res => {
        if (res.success) {
            window.open(res.data)
        }
      })
    },
    showAddDialog() {
      this.fileList = []
      this.fileList2 = []
      this.fileList3 = []
      this.fileList4 = []
      this.fileList5 = []
      this.fileList6 = []
      this.dialogAddVisible = true
      this.queryData.currentPage = 1
      this.queryData.pageSize = this.pageSizes[0]
      this.editing = false
    },
    // 多选按钮
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleRemove(file, fileList) {
      this.fileList = []
    },
    handleRemove2(file, fileList) {
      this.fileList2 = []
    },
    handleRemove3(file, fileList) {
      this.fileList3 = []
    },
    handleRemove4(file, fileList) {
      this.fileList4 = []
    },
    handleRemove5(file, fileList) {
      this.fileList5 = []
    },
    handleRemove6(file, fileList) {
      this.fileList6 = []
    }
  }
}
</script>
